#include "Light.h"

#include <iostream>

unsigned int Light::numLights = 0;

Light::Light() : 
m_pos(0.0f, 0.0f, 0.0f),
m_color(1.0f, 1.0f, 1.0f), 
m_power(10.0f)
{
    setUniformValues();
    ++numLights;
}

Light::Light(const vec3& pos, const vec3& color, const float& power) : 
m_pos(pos), 
m_color(color), 
m_power(power)
{
    setUniformValues();
    ++numLights;
}

Light::~Light()
{
}

Light& Light::operator=(const Light& rhs)
{
    if (this == &rhs)
    {
        return *this;
    }

    m_pos = rhs.getPos();
    m_color = rhs.getColor();
    m_power = rhs.getPower();
    m_uniPos = rhs.getUniform(POS);
    m_uniColor = rhs.getUniform(COLOR);
    m_uniPower = rhs.getUniform(POWER);

    return *this;
}

Light::Light(const Light& rhs)
{
    m_pos = rhs.getPos();
    m_color = rhs.getColor();
    m_power = rhs.getPower();
    m_uniPos = rhs.getUniform(POS);
    m_uniColor = rhs.getUniform(COLOR);
    m_uniPower = rhs.getUniform(POWER);
}

void Light::setPos(const vec3& pos)
{
    m_pos = pos;
}

void Light::setColor(const vec3& color)
{
    m_color = color;
}

void Light::setPower(const float& power)
{
    m_power = power;
}

vec3 Light::getPos() const
{
    return m_pos;
}

vec3 Light::getColor() const
{
    return m_color;
}

float Light::getPower() const
{
    return m_power;
}

string Light::getUniform(const Uniform uniform) const
{
    switch (uniform)
    {
    case POS:
        return m_uniPos;
    case COLOR:
        return m_uniColor;
    case POWER:
        return m_uniPower;
    default:
        std::cerr << "Invalid uniform request." << std::endl;
        return "Err.";
    };
}

void Light::setUniformValues()
{
    m_uniPos = "lights[" + uintToString(numLights) + "].pos";
    m_uniColor = "lights[" + uintToString(numLights) + "].color";
    m_uniPower = "lights[" + uintToString(numLights) + "].power";
}